package cn.fcq.system.service.impl;

import cn.fcq.basic.service.impl.BaseServiceImpl;
import cn.fcq.system.domain.DictionaryDetail;
import cn.fcq.system.domain.DictionaryType;
import cn.fcq.system.mapper.DictionaryDetailMapper;
import cn.fcq.system.mapper.DictionaryTypeMapper;
import cn.fcq.system.service.IDictionaryTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;

@Service
public class DictionaryTypeServiceImpl extends BaseServiceImpl<DictionaryType>implements IDictionaryTypeService {
    @Autowired
    private DictionaryTypeMapper dictionaryTypeMapper;
    @Autowired
    private DictionaryDetailMapper dictionaryDetailMapper;

    @Override
    @Transactional
    public void removeById(Long id) {
        Long[] ids = dictionaryDetailMapper.loadByTypeId(id);
        if(ids.length != 0){
            dictionaryDetailMapper.batchRemove(Arrays.asList(ids));
        }
        dictionaryTypeMapper.deleteById(id);
    }


}
